package com.freeter.modules.cityrecord.controller;

import java.util.Arrays;

import com.freeter.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.freeter.common.utils.JQPageInfo;
import com.freeter.common.mpextend.parser.ParseWrapper;
import com.freeter.common.utils.PageInfo;


import com.freeter.modules.cityrecord.entity.CitiesEntity;
import com.freeter.modules.cityrecord.entity.view.CitiesView;
import com.freeter.modules.cityrecord.entity.model.CitiesModel;

import com.freeter.modules.cityrecord.service.CitiesService;
import com.freeter.common.utils.PageUtils;
import com.freeter.common.utils.R;
import com.freeter.common.utils.MPUtil;



/**
 * 行政区域地州市信息表
 * 后端接口
 * @author xuchen
 * @email 171998110@qq.com
 * @date 2019-04-07 15:32:47
 */
@RestController
@RequestMapping("cityrecord/cities")
@SuppressWarnings({"unchecked","rawtypes"})
public class CitiesController {
    @Autowired
    private CitiesService citiesService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @RequiresPermissions("cityrecord:cities:list")
    public PageUtils page(JQPageInfo jqPageInfo,CitiesModel cities){
        EntityWrapper< CitiesEntity> ew = ParseWrapper.parseWrapper(cities);
     	PageInfo pageInfo = new PageInfo(jqPageInfo);
     	PageUtils page = citiesService.queryPage(pageInfo, ew);
    
        return page;
        
    }

	/**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("cityrecord:cities:list")
    public R list( CitiesModel cities){
       	EntityWrapper< CitiesEntity> ew = ParseWrapper.parseWrapper(cities);
        return R.ok().put("data",  citiesService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    @RequiresPermissions("cityrecord:cities:info")
    public R query(CitiesEntity cities){
        EntityWrapper< CitiesEntity> ew = ParseWrapper.parseWrapper(cities);
		CitiesView  citiesView =  citiesService.selectView(ew);
		return R.ok("查询行政区域地州市信息表成功").put("data",  citiesView);
    }
	
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("cityrecord:cities:info")
    public R info(@PathVariable("id") Integer id){
        CitiesEntity cities = citiesService.selectById(id);

        return R.ok().put("cities", cities);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("cityrecord:cities:save")
    public R save(@RequestBody CitiesEntity cities){
    	ValidatorUtils.validateEntity(cities);
        citiesService.insert(cities);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("cityrecord:cities:update")
    public R update(@RequestBody CitiesEntity cities){
        ValidatorUtils.validateEntity(cities);
        citiesService.updateAllColumnById(cities);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("cityrecord:cities:delete")
    public R delete(@RequestBody Integer[] ids){
        citiesService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
